<?php
namespace app\modules\epi\controllers;

use Yii;
use yii\db\Expression;
use app\models\DealLogSearch;
use app\models\DealLog;
use ac\controllers\AuthController;
use ac\component\exception\ErrMap;
use ac\component\tool\Tool;
use app\models\OperationLog;
use yii\helpers\Html;


class DealController extends AuthController
{
    /*列表*/
    public function actionDealList()
    {
        if(isset($this->get['page'])){
            $currPage = intval($this->get['page']?$this->get['page']:1);
        }else{
            $currPage = 1;
        }
        if(isset($this->get['pagesize'])){
            $pageSize = intval($this->get['pagesize']?$this->get['pagesize']:Tool::getPageSize());
        }else{
            $pageSize = Tool::getPageSize();
        }
        // P($this->get);
        $search = (new DealLogSearch())->search($this->get);
        if($search === false){//验证搜索参数不通过
            $count = 0;
            $dealList = array();
        }else{
            $count = $search->count();
            $dealList = $search->select(['deal_id', '{{%pj8_deal_log}}.member_id', 'order_id', 'orderid', 'money', 'balance', 'pay_status', 'flag', 'way', 'remark', 'callback_time', '{{%pj8_deal_log}}.add_time'])
                            ->joinWith('member')
                            ->offset($pageSize*($currPage-1))->limit($pageSize)
                            ->orderBy([
                                'deal_id' => SORT_DESC
                            ])
                            // ->createCommand()->getRawSql();
                            ->asArray()->all();
        }
        foreach($dealList as $k => $v) {
            $dealList[$k]['money'] /= 100;
            $dealList[$k]['balance'] /= 100;
            $dealList[$k]['membername'] = $v['member']['nickname'];
            unset($dealList[$k]['member']);
        }
        // P($dealList);
        $res = array(
            'list' => $dealList,
            'pageInfo' => array(
                'count' => intval($count),
                'currPage' => $currPage,
                'pageSize' => $pageSize,
            ),
        );
        return Tool::showRes([0, '获取成功'], $res);
    }

}
